<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="zh-cn">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<title>中国象棋 | 用户注册</title>
<meta name="description" content="Custom Login Form Styling with CSS3" />
<meta name="keywords" content="css3, login, form, custom, input, submit, button, html5, placeholder" />
<meta name="author" content="Codrops" />
<link rel="shortcut icon" href="../favicon.ico"> 
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="js/modernizr.custom.63321.js"></script>
<!--[if lte IE 7]><style>.main{display:none;} .support-note .note-ie{display:block;}</style><![endif]-->
</head>
  <body>
    <div id="Layer" style="position:absolute; left:0px; top:0px; width:100%; height:100%">
     <img src="Floor.jpg" width="100%" height="100%"/>
    </div>
  <center>
<div class="form-4">
<h1>欢   迎   注   册</h1>
<br/>
<br/>
<br/>
<tr>
<td>用户名：</td>
<td><input type="text" id="username" required/>
</td>
</tr>
<tr>
<td>密码：</td>
<td><input type="password" id="password" required/>
</td>
</tr>
<tr>
<td>确认密码：</td>
<td><input type="password" id="confirmPassword" required/>
</td>
</tr>
<tr>
<td>性别：</td>
<td>
<select id="sex" required>
 <option value="M" selected>男</option>
 <option value="F">女</option>
</select><br>
</td>
</tr>
    <tr>
    <td colspan="2" align="center">　<input type="submit" id="submit" value="注册"></td>
    </tr>
</form>
  </center>
  </body>

<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(function() {

$('#submit').click(function() {
    var username = $('#username').val();
    var password = $('#password').val();
    var confirmPassword = $('#confirmPassword').val();
    if (password != confirmPassword) {
        alert('两次输入的密码不一致！请检查');
        return;
    }
    var sex = $('#sex').val();
    $.ajax({
        type: 'POST',
        url: 'register.jsp',
        data: {
            username: username,
            password: password,
            sex: sex,
        },
        success: function(res) {
            if (res.substr(0, 2) == 'OK')
                window.location.href = 'login.html';
            else
                alert(res);
        },
        error: function(xhr, opt, err) {
            alert('HTTP ERROR ' + xhr.status);
        },
    });
});

});
</script>
</html>
